import { alova } from '../../request';

/** get menu list */
export function listMenu() {
  return alova.Get<Api.Row[]>('/permission/menu/list');
}

/** get all pages */
export function listPages() {
  return alova.Get<string[]>('/permission/getAllPages', { cacheFor: null });
}

/** get menu tree */
export function treeMenu() {
  return alova.Get<Api.Node[]>('/permission/menu/tree', { cacheFor: null });
}

/** add menu */
export function createMenu(data: Api.Model) {
  return alova.Post<boolean>('/permission/menu/create', data, { name: 'createMenu' });
}

/** menu drawer get menu info */
export function fetchMenu(params: Api.GetParams) {
  return alova.Get<Api.Model>('/permission/menu/get', {
    params,
    cacheFor: null
  });
}

/** edit update menu info */
export function updateMenu(data: Api.Model) {
  return alova.Post<boolean>('/permission/menu/update', data, { name: 'updateMenu' });
}

/** edit delete menu button */
export function deleteMenu(params: Api.DeleteParams) {
  return alova.Post<boolean>('/permission/menu/delete', undefined, { params });
}

// =============== Permission Begin ===============

/** get permission page list */
export function listPermission(params?: Api.SearchParams) {
  return alova.Get<Api.Node[]>('/permission/button/list', { params });
}

/** add permission button */
export function createPermission(data: Api.Model) {
  return alova.Post<boolean>('/permission/button/create', data);
}

/** edit update permission button info */
export function updatePermission(data: Api.Model) {
  return alova.Post<boolean>('/permission/button/update', data);
}

/** edit delete permission button */
export function deletePermission(data: Api.DeleteParams) {
  return alova.Post<boolean>('/permission/button/delete', data);
}

export function paginatePermission(params?: Api.Manage.PermissionSearchParams) {
  return alova.Get<Api.Manage.PermissionList>('/permission/button/paginate', { params });
}

// =============== Permission End  ===============
